Ext.define('AM.controller.MenuController',{ 
    extend: 'Ext.app.Controller', 
	stores:[
 			'MenuStore'	
 	],
 	views:[
 		'MenuView'	
 	],	
//    refs:[ 
//        {ref: 'menuView',selector: 'amtablepanel'},
//        {ref: 'tabPanel',selector:'amtablepanel'}
//    ], 
    init:function(){ 
        this.control({ 
            'menuView': { 
				itemclick:this.loadMenu 
            } 
        }) 
    }, 
    loadMenu:function(selModel, record,result){ 
	var add=false;
	var edit=false;
	var drop=false;
	var search=true;
        if (record.get('leaf')) { 
            var moduleTabId ='tab-' +record.get('id');
            var centmain = Ext.getCmp("center-region-container"); 
//             var tab = main.getComponent(moduleTabId);
//             var tab = centmain.child('#'+moduleTabId+'');
             var tab = centmain.queryById(moduleTabId);
            if(!tab){
             var p = {
                    title:record.get('text'),
                 	 id:moduleTabId,
//                    itemId:moduleTabId,
                    closable:true,
                    autoDestroy:true
                };
            
             	 var  panel=Ext.create( 'AM.view.'+record.get('url'),p);
             	  centmain.add(panel).show();
//        		  centmain.setActiveTab(panel);
	                 
            }else{ 
//                main.setActiveTab(panel); 	
				centmain.setActiveTab(tab);  

            } 
         
	     	 if( record.get('add')=='true'){	
	          	    add=true;
		      }if(record.get('edit')=='true'){
		        	edit=true;
		       } if(record.get('delete')=='true'){
		       		  drop=true;
		        }if(record.get('search')=='true'){
		        	 search=false;
		        }
			 if(Ext.getCmp(moduleTabId+"_add")!=null){
			 	
				Ext.getCmp(moduleTabId+"_add").setVisible(add);
			 }
	         if(Ext.getCmp(moduleTabId+"_edit")!=null){
	         	 Ext.getCmp(moduleTabId+"_edit").setVisible(edit);
	         }
	         if(Ext.getCmp(moduleTabId+"_delete")!=null){
	         	Ext.getCmp(moduleTabId+"_delete").setVisible(drop);
	         }
	          if(Ext.getCmp(moduleTabId+"_search")!=null){
//	         	Ext.getCmp(moduleTabId+"_search").setVisible(search);
	         	Ext.getCmp(moduleTabId+"_search").setDisabled(search);
	         }
          
      }  

    }
}) 